package com.csii.mobilebanking.user;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import com.csii.mobilebanking.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ExpListAdt extends BaseExpandableListAdapter {

	private Context mContext;
	private List<GroupBean> datasList;

	public ExpListAdt(Context context, List<GroupBean> addDatas) {
		this.mContext = context;
		datasList = addDatas;
	}

	// -----------------Child----------------//
	@Override
	public Object getChild(int groupPosition, int childPosition) {

		return datasList.get(groupPosition).getListChildBeans()
				.get(childPosition);
	}

	@Override
	public long getChildId(int groupPosition, int childPosition) {
		return childPosition;
	}

	@Override
	public View getChildView(int groupPosition, int childPosition,
			boolean isLastChild, View convertView, ViewGroup parent) {
		View view = convertView;
		if (view == null) {
			LayoutInflater inflater = (LayoutInflater) mContext
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			view = inflater.inflate(R.layout.exp_child, null);
		}
		TextView tv = (TextView) view.findViewById(R.id.ctv);
		tv.setText(((ChildBean) getChild(groupPosition, childPosition))
				.getName().toString());
		return view;
	}

	@Override
	public int getChildrenCount(int groupPosition) {
		return datasList.get(groupPosition).getListChildBeans().size();
	}

	// ----------------Group----------------//
	@Override
	public Object getGroup(int groupPosition) {
		return datasList.get(groupPosition);
	}

	@Override
	public int getGroupCount() {

		return datasList.size();
	}

	@Override
	public long getGroupId(int groupPosition) {

		return groupPosition;
	}

	@Override
	public View getGroupView(int groupPosition, boolean isExpanded,
			View convertView, ViewGroup parent) {
		View view = convertView;
		if (view == null) {
			LayoutInflater inflater = (LayoutInflater) mContext
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			view = inflater.inflate(R.layout.exp_group, null);
		}
		TextView tv = (TextView) view.findViewById(R.id.gtv);
		LinearLayout l_group = (LinearLayout) view.findViewById(R.id.l_group);
		tv.setText((((GroupBean) getGroup(groupPosition)).getName()).toString());
		// 判断分组是否展开，分别传入不同的图片资源--xml 控制
		if (isExpanded) {
			l_group.setBackgroundResource(R.drawable.expanded);
		} else {
			l_group.setBackgroundResource(R.drawable.closed);
		}
		return view;
	}

	@Override
	public boolean hasStableIds() {
		return true;
	}

	@Override
	public boolean isChildSelectable(int groupPosition, int childPosition) {
		return true;
	}

}
